package thread.lock;

/*
模拟死锁
 */
public class DeadLock {
    public static final Object MONITOR1 = new Object();
    public static final Object MONITOR2 = "new Object()";

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (MONITOR1) {
                System.out.println(Thread.currentThread().getName() + "拿到了一号锁");
                synchronized (MONITOR2) {
                    System.out.println(Thread.currentThread().getName() + "拿到了二号锁");
                }
            }
        }, "MONITOR1").start();

        new Thread(() -> {
            synchronized (MONITOR2) {
                System.out.println(Thread.currentThread().getName() + "拿到了二号锁");
                synchronized (MONITOR1) {
                    System.out.println(Thread.currentThread().getName() + "拿到了一号锁");
                }
            }
        }, "MONITOR2").start();
    }

}
